package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.quartz.task.RyTask;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TTerminalVo;
import com.ruoyi.system.basicInformation.bo.TTerminalQueryBo;
import com.ruoyi.system.basicInformation.bo.TTerminalAddBo;
import com.ruoyi.system.basicInformation.bo.TTerminalEditBo;
import com.ruoyi.system.basicInformation.service.ITTerminalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 终端注册Controller
 * 
 * @author ruoyi
 * @date 2021-05-21
 */
@Api(value = "终端注册控制器", tags = {"终端注册管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/terminal")
public class TTerminalController extends BaseController {

    private final ITTerminalService iTTerminalService;

    /**
     * 查询终端注册列表
     */
    @ApiOperation("查询终端注册列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:list')")
    @GetMapping("/list")
    public TableDataInfo<TTerminalVo> list(TTerminalQueryBo bo) {
        startPage();
        List<TTerminalVo> list = iTTerminalService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 终端上线情况统计
     */
    @ApiOperation("终端上线情况统计")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:terminal_inline_statisti')")
    @GetMapping("/terminalInlineStatistics")
    public TableDataInfo<TTerminalVo> terminalInlineStatistics(TTerminalQueryBo bo) {
        startPage();
        List<TTerminalVo> list = iTTerminalService.terminalInlineStatistics(bo);
        return getDataTable(list);
    }

    /**
     * 终端上线情况统计
     */
    @ApiOperation("终端上线率")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:terminal_inline_rate')")
    @GetMapping("/terminalOnlineRate")
    public TableDataInfo<TTerminalVo> terminalOnlineRate(TTerminalQueryBo bo) {
        startPage();
        List<TTerminalVo> list = iTTerminalService.terminalOnlineRate(bo);
        return getDataTable(list);
    }

    /**
     * 终端上线情况子对象统计
     */
    @ApiOperation("终端上线情况子对象统计")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:terminal_inline_statisti')")
    @GetMapping("/terminalInlineChildrenStatistics")
    public TableDataInfo<TTerminalVo> terminalInlineChildrenStatistics(TTerminalQueryBo bo) {
        List<TTerminalVo> list = iTTerminalService.terminalInlineChildrenStatistics(bo);
        return getDataTable(list);
    }

    /**
     * 导出终端注册列表
     */
    @ApiOperation("导出终端注册列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:export')")
    @Log(title = "终端注册", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TTerminalVo> export(TTerminalQueryBo bo) {
        List<TTerminalVo> list = iTTerminalService.queryList(bo);
        ExcelUtil<TTerminalVo> util = new ExcelUtil<TTerminalVo>(TTerminalVo.class);
        return util.exportExcel(list, "终端注册");
    }

    /**
     * 获取终端注册详细信息
     */
    @ApiOperation("获取终端注册详细信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:query')")
    @GetMapping("/{id}")
    public AjaxResult<TTerminalVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTTerminalService.queryById(id));
    }

    /**
     * 新增终端注册
     */
    @ApiOperation("新增终端注册")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:add')")
    @Log(title = "终端注册", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TTerminalAddBo bo) {
        return toAjax(iTTerminalService.insertByAddBo(bo) ? 1 : 0);
    }


    /**
     * 修改终端注册
     */
    @ApiOperation("修改终端注册")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:edit')")
    @Log(title = "终端注册", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TTerminalEditBo bo) {
        return toAjax(iTTerminalService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除终端注册
     */
    @ApiOperation("删除终端注册")
    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:remove')")
    @Log(title = "终端注册" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTTerminalService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**frontierCommand
     * 查询终端注册列表
     */
    @ApiOperation("查询终端注册列表")
//    @PreAuthorize("@ss.hasPermi('basicInformation:terminal:list')")
    @GetMapping("/listTouristCurrentPoint")
    public TableDataInfo<TTerminalVo> listTouristCurrentPoint() {
        List<TTerminalVo> list = iTTerminalService.listTouristCurrentPoint();
        return getDataTable(list);
    }
}
